<template>
  <n-config-provider class="min-h-screen" :theme="currentTheme">
    <n-message-provider>
      <n-dialog-provider>
        <loading-provider>
          <n-notification-provider>
            <router-view v-slot="{ Component }">
              <keep-alive>
                <component
                  :is="Component"
                  v-if="$route.meta.keepAlive"
                  :key="$route.path"
                />
              </keep-alive>
            </router-view>
            <router-view v-slot="{ Component }">
              <component
                :is="Component"
                v-if="!$route.meta.keepAlive"
                :key="$route.path"
              />
            </router-view>
          </n-notification-provider>
        </loading-provider>
      </n-dialog-provider>
    </n-message-provider>
    <n-global-style />
  </n-config-provider>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
import { useAppStore } from '@/stores'

export default defineComponent({
  name: 'App',
  setup() {
    const $route = useRoute()
    const appStore = useAppStore()
    const { currentTheme } = storeToRefs(appStore)
    return {
      $route,
      currentTheme
    }
  }
})
</script>

<style lang="scss">
@import '@/styles/public.scss';
</style>
